package com.example.armmvvm.ui.constraint.statefallview

import android.view.View
import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.LifecycleOwner
import com.example.arm.ext.dpInt
import com.example.armmvvm.R
import com.example.armmvvm.databinding.LayoutBottomBehaviorTestBinding
import com.example.armmvvm.ui.fallview.BottomFallView
import com.example.armmvvm.ui.fallview.BottomFallViewSetting
import com.example.armmvvm.ui.fallview.FallViewMode
import com.example.armmvvm.ui.fallview.MiddleHeightCalc

/**
 *  author : yanghaozhang
 *  date : 2022/10/18 17:48
 *  description :
 */
class ThreeStateFallView(lifecycleOwner: LifecycleOwner, viewContainer: ViewGroup) :
    BottomFallView(lifecycleOwner, viewContainer, R.layout.layout_bottom_behavior_test) {

    lateinit var binding: LayoutBottomBehaviorTestBinding

    override fun updateView(view: View) {
        binding = LayoutBottomBehaviorTestBinding.bind(view).apply {
            scrollView.updateLayoutParams {
                height = ViewGroup.LayoutParams.WRAP_CONTENT
            }
            blankView.updateLayoutParams {
                height = 950.dpInt
            }
            tvContent.text = "ThreeStateFallView"
            tvContent.setOnClickListener {
                ThreeNoTopStateFallView(lifecycleOwner, viewContainer).show()
            }
            root.setPadding(0, 0, 0, 30.dpInt)
        }
    }

    override fun bottomFallViewSetting(view: View): BottomFallViewSetting {
        return BottomFallViewSetting(view).apply {
            mode = FallViewMode.THREE_STATE
            calcHeight = {
                peekHeight = binding.tvContent.height
            }
            expandedOffset = 30.dpInt
            middleHeightCalc = MiddleHeightCalc.withDefiniteMiddleHeight(220.dpInt)
        }
    }

    override fun onDismiss() {
        super.onDismiss()
        binding.root.setPadding(0, 0, 0, 0)
    }
}